package com.zoke.daycarpool.adapter;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zoke.daycarpool.R;
import com.zoke.daycarpool.config.ImageConfig;
import com.zoke.daycarpool.domain.FeedBackBeen;
import com.zoke.daycarpool.domain.UserInstense;
import com.zoke.support.base.BaseObjectListAdapter;
import com.zoke.support.utils.ViewHolder;

public class FeeBackAdapter extends BaseObjectListAdapter {

	private static final int MESSAGE_TYPE_RECV_TXT = 0;

	public FeeBackAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	@Override
	public View getItemView(int position, View convertView, ViewGroup parent) {
		FeedBackBeen feedB = (FeedBackBeen) mDatas.get(position);
		if (feedB.getType() == MESSAGE_TYPE_RECV_TXT) {
			convertView = getConvertView(null, R.layout.listview_item_received);
		} else {
			convertView = getConvertView(null, R.layout.listview_item_send);
		}
		// 获取左控件
		TextView mTimeTv = ViewHolder.get(convertView, R.id.timestamp);
		TextView mTextTv = ViewHolder.get(convertView, R.id.tv_chatcontent);
		ImageView miv = ViewHolder.get(convertView, R.id.iv_userhead);
		if (feedB.getType() != MESSAGE_TYPE_RECV_TXT) {
			ImageLoader.getInstance().displayImage(
					UserInstense.getInstense(mContext).getUser().getPhoto(),
					miv, ImageConfig.getHeadOptions());
		} else {
			ImageLoader.getInstance().displayImage(
					"drawable://" + R.drawable.logo, miv,
					ImageConfig.getHeadOptions());
		}
		SimpleDateFormat sdf = new SimpleDateFormat("yy年MM月dd日 HH:mm:ss");
		Date data = new Date(feedB.getTime());
		mTimeTv.setText("" + sdf.format(data));
		mTextTv.setText("" + feedB.getContent());
		return convertView;
	}

}
